# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="x86_64 Linux hosted cross toolchains"
HOMEPAGE="https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads"
SRC_URI="https://developer.arm.com/-/media/Files/downloads/gnu/${PV}.rel1/binrel/arm-gnu-toolchain-${PV}.rel1-x86_64-${PN}.tar.xz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64 x86"
RESTRICT="binchecks bindist mirror strip"
IUSE=""

S=${WORKDIR}

OPT_DIR="opt/arm-gnu-toolchain"

RDEPEND="sys-libs/ncurses-compat"

src_unpack() {
	# skip
	:
}


src_install() {
	dodir /

	mkdir -p "${D}/${OPT_DIR}" || die

	cd "${D}/${OPT_DIR}" || die

	unpack ${A} || die

	mv "arm-gnu-toolchain-${PV}.rel1-x86_64-${PN}" ${P} || die

	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-addr2line"         /usr/bin/arm-none-eabi-addr2line
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-ar"                /usr/bin/arm-none-eabi-ar
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-as"                /usr/bin/arm-none-eabi-as
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-c++"               /usr/bin/arm-none-eabi-c++
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-c++filt"           /usr/bin/arm-none-eabi-c++filt
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-cpp"               /usr/bin/arm-none-eabi-cpp
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-elfedit"           /usr/bin/arm-none-eabi-elfedit
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-g++"               /usr/bin/arm-none-eabi-g++
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gcc"               /usr/bin/arm-none-eabi-gcc
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gcc-13.3.1"        /usr/bin/arm-none-eabi-gcc-13.3.1
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gcc-ar"            /usr/bin/arm-none-eabi-gcc-ar
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gcc-nm"            /usr/bin/arm-none-eabi-gcc-nm
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gcc-ranlib"        /usr/bin/arm-none-eabi-gcc-ranlib
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gcov"              /usr/bin/arm-none-eabi-gcov
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gcov-dump"         /usr/bin/arm-none-eabi-gcov-dump
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gcov-tool"         /usr/bin/arm-none-eabi-gcov-tool
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gdb"               /usr/bin/arm-none-eabi-gdb
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gdb-add-index"     /usr/bin/arm-none-eabi-gdb-add-index
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gdb-add-index-py"  /usr/bin/arm-none-eabi-gdb-add-index-py
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gdb-py"            /usr/bin/arm-none-eabi-gdb-py
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gfortran"          /usr/bin/arm-none-eabi-gfortran
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-gprof"             /usr/bin/arm-none-eabi-gprof
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-ld"                /usr/bin/arm-none-eabi-ld
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-ld.bfd"            /usr/bin/arm-none-eabi-ld.bfd
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-lto-dump"          /usr/bin/arm-none-eabi-lto-dump
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-nm"                /usr/bin/arm-none-eabi-nm
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-objcopy"           /usr/bin/arm-none-eabi-objcopy
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-objdump"           /usr/bin/arm-none-eabi-objdump
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-ranlib"            /usr/bin/arm-none-eabi-ranlib
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-readelf"           /usr/bin/arm-none-eabi-readelf
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-size"              /usr/bin/arm-none-eabi-size
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-strings"           /usr/bin/arm-none-eabi-strings
	dosym "../../${OPT_DIR}/${P}/bin/arm-none-eabi-strip"             /usr/bin/arm-none-eabi-strip

}
